<template>
	<view>
		<view>
			<button type="primary" size="mini"  @click="isshow = true">新增</button>
		</view>
		<view style="line-height: 60px;">
			<view v-for="item in dataList" :key="item._id">
				标题： {{item.title}}--- 内容  {{item.content}}
				<button type="warn" size="mini" @click="del(item._id)">删除</button>
			</view>
		</view>
		<view>
			<cc-popup :isShow='isshow' width="600px" height="346px" radius="16rpx">
				<view style="width: 260px;margin: auto;margin-top: 30px;">
					<input class="uni-search" type="text" v-model="form.title" placeholder="请输入标题" />
					<input class="uni-search" type="text" v-model="form.content" placeholder="请输入内容" />
				</view>
				<view class="buttonBox">
					<view class="buttonBoxLeft" @click="isshow = false">
						取消
					</view>
					<view class="buttonBoxRight" @click="add">
						确定
					</view>
				</view>
			</cc-popup>
		</view>
	</view>
</template>

<script>
	const selfProblem = uniCloud.importObject("self-problem")
	export default {
		data() {
			return {
				form: {
					title: "",
					content: ""
				},
				isshow: false,
				dataList: []
			}
		},
		methods: {
			getData(){
				selfProblem.getData().then(res => {
					this.dataList = res.data.data
				})
			},
			add(){
				if(this.form.title && this.form.content){
					selfProblem.add(this.form).then(res => {
						uni.showToast({
							title: "新增成功"
						})
						
						this.isshow = false
						
						setTimeout(() => {
							this.getData()
						}, 800)
					})
				}else {
					uni.showToast({
						title: "有未填内容",
						icon: "error"
					})
				}
			},
			del(id){
				selfProblem.del(id).then(res => {
					uni.showToast({
						title: "删除成功"
					})
					
					setTimeout(() => {
						this.getData()
					}, 800)
				})
			}
		},
		mounted() {
			this.getData()
		}
	}
</script>

<style>

</style>
